from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-25 14:05:47.292029
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 25, Jan, 2022
Time: 14:05:52
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.8400
Nobs: 547.000 HQIC: -48.2714
Log likelihood: 6382.51 FPE: 8.23729e-22
AIC: -48.5482 Det(Omega_mle): 6.99799e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.354321 0.069933 5.067 0.000
L1.Burgenland 0.106336 0.042516 2.501 0.012
L1.Kärnten -0.112458 0.022036 -5.103 0.000
L1.Niederösterreich 0.191687 0.088724 2.160 0.031
L1.Oberösterreich 0.129153 0.087651 1.473 0.141
L1.Salzburg 0.257929 0.044882 5.747 0.000
L1.Steiermark 0.031315 0.059194 0.529 0.597
L1.Tirol 0.102277 0.047763 2.141 0.032
L1.Vorarlberg -0.073371 0.042223 -1.738 0.082
L1.Wien 0.019876 0.078010 0.255 0.799
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059822 0.152046 0.393 0.694
L1.Burgenland -0.042542 0.092437 -0.460 0.645
L1.Kärnten 0.040599 0.047910 0.847 0.397
L1.Niederösterreich -0.205926 0.192900 -1.068 0.286
L1.Oberösterreich 0.456465 0.190567 2.395 0.017
L1.Salzburg 0.284362 0.097580 2.914 0.004
L1.Steiermark 0.113715 0.128697 0.884 0.377
L1.Tirol 0.306086 0.103845 2.948 0.003
L1.Vorarlberg 0.021572 0.091801 0.235 0.814
L1.Wien -0.024786 0.169606 -0.146 0.884
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197272 0.035655 5.533 0.000
L1.Burgenland 0.090559 0.021676 4.178 0.000
L1.Kärnten -0.007422 0.011235 -0.661 0.509
L1.Niederösterreich 0.234564 0.045235 5.185 0.000
L1.Oberösterreich 0.168657 0.044688 3.774 0.000
L1.Salzburg 0.039036 0.022882 1.706 0.088
L1.Steiermark 0.024277 0.030179 0.804 0.421
L1.Tirol 0.081473 0.024352 3.346 0.001
L1.Vorarlberg 0.055257 0.021527 2.567 0.010
L1.Wien 0.117966 0.039773 2.966 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118635 0.035812 3.313 0.001
L1.Burgenland 0.043431 0.021772 1.995 0.046
L1.Kärnten -0.013923 0.011284 -1.234 0.217
L1.Niederösterreich 0.172076 0.045434 3.787 0.000
L1.Oberösterreich 0.335953 0.044885 7.485 0.000
L1.Salzburg 0.099978 0.022983 4.350 0.000
L1.Steiermark 0.108721 0.030312 3.587 0.000
L1.Tirol 0.090847 0.024459 3.714 0.000
L1.Vorarlberg 0.059866 0.021622 2.769 0.006
L1.Wien -0.015906 0.039948 -0.398 0.690
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122828 0.067593 1.817 0.069
L1.Burgenland -0.046082 0.041093 -1.121 0.262
L1.Kärnten -0.045419 0.021298 -2.133 0.033
L1.Niederösterreich 0.141226 0.085754 1.647 0.100
L1.Oberösterreich 0.167398 0.084717 1.976 0.048
L1.Salzburg 0.282610 0.043379 6.515 0.000
L1.Steiermark 0.060138 0.057212 1.051 0.293
L1.Tirol 0.154764 0.046165 3.352 0.001
L1.Vorarlberg 0.094594 0.040810 2.318 0.020
L1.Wien 0.071578 0.075399 0.949 0.342
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.085098 0.052629 1.617 0.106
L1.Burgenland 0.021509 0.031996 0.672 0.501
L1.Kärnten 0.053059 0.016583 3.200 0.001
L1.Niederösterreich 0.190732 0.066770 2.857 0.004
L1.Oberösterreich 0.329421 0.065962 4.994 0.000
L1.Salzburg 0.035461 0.033776 1.050 0.294
L1.Steiermark 0.000548 0.044546 0.012 0.990
L1.Tirol 0.121276 0.035944 3.374 0.001
L1.Vorarlberg 0.065532 0.031775 2.062 0.039
L1.Wien 0.098914 0.058707 1.685 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173738 0.063697 2.728 0.006
L1.Burgenland 0.005235 0.038725 0.135 0.892
L1.Kärnten -0.065382 0.020071 -3.258 0.001
L1.Niederösterreich -0.109938 0.080812 -1.360 0.174
L1.Oberösterreich 0.215233 0.079835 2.696 0.007
L1.Salzburg 0.052447 0.040879 1.283 0.200
L1.Steiermark 0.250228 0.053915 4.641 0.000
L1.Tirol 0.498510 0.043504 11.459 0.000
L1.Vorarlberg 0.065990 0.038458 1.716 0.086
L1.Wien -0.082290 0.071054 -1.158 0.247
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159230 0.070450 2.260 0.024
L1.Burgenland -0.006873 0.042830 -0.160 0.873
L1.Kärnten 0.062517 0.022199 2.816 0.005
L1.Niederösterreich 0.179643 0.089379 2.010 0.044
L1.Oberösterreich -0.065187 0.088298 -0.738 0.460
L1.Salzburg 0.205597 0.045213 4.547 0.000
L1.Steiermark 0.137801 0.059631 2.311 0.021
L1.Tirol 0.055885 0.048116 1.161 0.245
L1.Vorarlberg 0.143617 0.042535 3.376 0.001
L1.Wien 0.130986 0.078586 1.667 0.096
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394340 0.041137 9.586 0.000
L1.Burgenland -0.002661 0.025009 -0.106 0.915
L1.Kärnten -0.020562 0.012962 -1.586 0.113
L1.Niederösterreich 0.203194 0.052191 3.893 0.000
L1.Oberösterreich 0.241671 0.051559 4.687 0.000
L1.Salzburg 0.033070 0.026401 1.253 0.210
L1.Steiermark -0.017462 0.034820 -0.502 0.616
L1.Tirol 0.086845 0.028096 3.091 0.002
L1.Vorarlberg 0.051320 0.024837 2.066 0.039
L1.Wien 0.033991 0.045888 0.741 0.459
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.034930 0.101752 0.167012 0.134538 0.091697 0.081286 0.030744 0.213497
Kärnten 0.034930 1.000000 -0.026319 0.133103 0.047462 0.084820 0.445635 -0.069390 0.093502
Niederösterreich 0.101752 -0.026319 1.000000 0.309579 0.125984 0.267211 0.068262 0.155810 0.282439
Oberösterreich 0.167012 0.133103 0.309579 1.000000 0.215822 0.293194 0.170955 0.134823 0.236362
Salzburg 0.134538 0.047462 0.125984 0.215822 1.000000 0.126937 0.088521 0.105187 0.126776
Steiermark 0.091697 0.084820 0.267211 0.293194 0.126937 1.000000 0.136742 0.103689 0.031084
Tirol 0.081286 0.445635 0.068262 0.170955 0.088521 0.136742 1.000000 0.063898 0.150674
Vorarlberg 0.030744 -0.069390 0.155810 0.134823 0.105187 0.103689 0.063898 1.000000 -0.005078
Wien 0.213497 0.093502 0.282439 0.236362 0.126776 0.031084 0.150674 -0.005078 1.000000